package com.hzlj.position.job.job;

import com.fz.common.redis.annotation.SyncLock;
import com.hzlj.position.locate.common.enums.AbnMissingStep;
import com.hzlj.position.locate.service.AbnMissingJzryNoticeService;
import com.hzlj.position.locate.service.AbnMissingJzryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * job 建议凌晨1点开始执行
 **/
@Slf4j
@Component
public class AbnMissingJob {
    @Resource
    private AbnMissingJzryService abnMissingJzryService;
    @Resource
    private AbnMissingJzryNoticeService abnMissingJzryNoticeService;

    @SyncLock(lockMs = 60000)
    @Scheduled(cron = "${job.abn.missing:0 0 8 * * ?}")
    public void abn() {
        long start = System.currentTimeMillis();
        log.info("任务开始执行[疑似失联]");
        abnMissingJzryService.abn();
        log.info("任务结束执行[疑似失联],cost={}", System.currentTimeMillis() - start);
    }


    @SyncLock(lockMs = 600000)
    @Scheduled(cron = "${job.abn.missing.notice:0 0/1 8-10 * * ?}")
    public void noticeStep1() {
        long start = System.currentTimeMillis();
        log.info("任务开始执行[疑似失联:step1]");
        abnMissingJzryNoticeService.notice(AbnMissingStep.STEP1);
        log.info("任务结束执行[疑似失联:step1],cost={}", System.currentTimeMillis() - start);
    }

    @SyncLock(lockMs = 600000)
    @Scheduled(cron = "${job.abn.missing.notice:0 0/1 8-10 * * ?}")
    public void noticeStep2() {
        long start = System.currentTimeMillis();
        log.info("任务开始执行[疑似失联:step2]");
        abnMissingJzryNoticeService.notice(AbnMissingStep.STEP2);
        log.info("任务结束执行[疑似失联:step2],cost={}", System.currentTimeMillis() - start);
    }

    @SyncLock(lockMs = 600000)
    @Scheduled(cron = "${job.abn.missing.notice:0 0/1 8-10 * * ?}")
    public void noticeStep3() {
        long start = System.currentTimeMillis();
        log.info("任务开始执行[疑似失联:step3]");
        abnMissingJzryNoticeService.notice(AbnMissingStep.STEP3);
        log.info("任务结束执行[疑似失联:step3],cost={}", System.currentTimeMillis() - start);
    }

}
